package com.mdinfo.system.service.impl;

import com.mdinfo.system.service.IDemoService;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2018/1/30.
 */
@Service
public class DemoService implements IDemoService {


    @Async("businessAsync")
    public ListenableFuture<String> test02() {
        String result = execute();
        return new AsyncResult<>(result);
    }

    private String execute(){

        System.out.println("service线程:"+Thread.currentThread().getName());
/*        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes)attributes;
        HttpServletRequest request = requestAttributes.getRequest();
        String name = request.getParameter("name");
        System.out.println("name:"+name);*/
        try {
            Thread.sleep(10000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "abc";
    }
}
